/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Memory.java
 *
 * Created on Sep 24, 2011, 12:28:37 PM
 */
package aor2.gui.mem;

import aor2.assembly.Assembler;
import aor2.memory.TestMemory;
import java.util.Formatter;

/**
 * 
 * @author Yogi
 */
public class Memory extends javax.swing.JFrame {
	private aor2.memory.Memory mem;

	public void setTextArea() {
		StringBuffer buff = new StringBuffer();
		for (int i = 0; i < mem.capacity(); i++) {
			Formatter frm = new Formatter();
			String format = String.format("%%0%dx", 4);
			String result = String.format(format, mem.readWord(i) & 0xFFFF);
			buff.append("MemAdr   ").append(Integer.toHexString(i))
					.append(":   ").append(result).append('\n');
		}
		jTextArea1.setText(buff.toString());
	}

	/** Creates new form Memory */
	public Memory(aor2.memory.Memory mem) {
		this.mem = mem;
		initComponents();
		setTextArea();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jScrollPane1 = new javax.swing.JScrollPane();
		jTextArea1 = new javax.swing.JTextArea();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		jTextArea1.setColumns(20);
		jTextArea1.setRows(5);
		jScrollPane1.setViewportView(jTextArea1);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addGap(40, 40, 40)
						.addComponent(jScrollPane1,
								javax.swing.GroupLayout.PREFERRED_SIZE, 316,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(44, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout.createParallelGroup(
				javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addGap(30, 30, 30)
						.addComponent(jScrollPane1,
								javax.swing.GroupLayout.PREFERRED_SIZE, 226,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addContainerGap(44, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>//GEN-END:initComponents

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				// TODO punjenje memorije
				aor2.memory.Memory mem = TestMemory.getInstance();
				Assembler
						.load("E:\\eclispe _ proj\\aor2\\src\\aor2\\assembly\\amsTest1.txt",
								mem, 0);
				new Memory(mem).setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTextArea jTextArea1;
	// End of variables declaration//GEN-END:variables
}
